package Base.基本的三种创建方法;

import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;

/**
 * @author 陈鹏
 */
public class CallableTest {
    public static void main(String[] args) {
        TicketWindow3 tw3=new TicketWindow3();
        //futuretask创建多少就是多少个线程
        FutureTask<Object> ft1=new FutureTask<Object>(tw3);
        FutureTask<Object> ft2=new FutureTask<Object>(tw3);
        FutureTask<Object> ft3=new FutureTask<Object>(tw3);
        FutureTask<Object> ft4=new FutureTask<Object>(tw3);
        new Thread(ft1,"窗口1").start();
        new Thread(ft2,"窗口2").start();
        new Thread(ft3,"窗口3").start();
        new Thread(ft4,"窗口4").start();
//        System.out.println(ft1.get());
    }
}

class TicketWindow3 implements Callable{
    private int tickets=100;
    @Override
    public Object call() throws Exception {
        while (true){
            if (tickets>0){
                System.out.println(Thread.currentThread().getName()+"正在出售第"+tickets--+"张票");
            }
        }
    }
}
